package com.atguigu.gmall.wms.config;

import com.atguigu.gmall.common.consts.GmallConsts;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {


    @Bean
    public Exchange  delayCloseOrderExchange(){
        return ExchangeBuilder.topicExchange("order.close.exchange")
                    .durable(true)
                    .ignoreDeclarationExceptions()
                    .build();
    }
    @Bean
    public Queue delayCloseOrderQueue(){
        return QueueBuilder.durable("order.close.queue")
                .ttl(60*60*1000)//一小时
                .deadLetterExchange(GmallConsts.MQ_ORDER_EXCHANGE) //死信交换机
                .deadLetterRoutingKey("stock.unlock")//死信路由key
                .build();
    }
    @Bean
    public Binding delayCloseOrderQueueBinding(Exchange  delayCloseOrderExchange,Queue delayCloseOrderQueue){
        return BindingBuilder.bind(delayCloseOrderQueue)
                .to(delayCloseOrderExchange)
                .with("order.close")
                .noargs();
    }
}
